package trabalho3;

import org.jtrace.Materials;
import org.jtrace.Scene;
import org.jtrace.cameras.Camera;
import org.jtrace.cameras.PinHoleCamera;
import org.jtrace.geometry.Plane;
import org.jtrace.geometry.Sphere;
import org.jtrace.lights.Light;
import org.jtrace.primitives.ColorRGB;
import org.jtrace.primitives.Point3D;
import org.jtrace.primitives.Vector3D;

public class JTrace {
	
    private static Interface window = new Interface(createScene());
    
    	
	static final int SPHERE1_RADIUS = 10;
	static final int SPHERE1_ORIGIN_X = -20;
	static final int SPHERE1_ORIGIN_Y = 0;
	static final int SPHERE1_ORIGIN_Z = 0;
	
	static final int SPHERE2_RADIUS = 20;
	static final int SPHERE2_ORIGIN_X = 0;
	static final int SPHERE2_ORIGIN_Y = 0;
	static final int SPHERE2_ORIGIN_Z = 0;
	
	static final int LIGHT_POSITION_X = 0;
	static final int LIGHT_POSITION_Y = 20;
	static final int LIGHT_POSITION_Z = -10;
	
    public static void main(final String[] args) {
        window.setVisible(true);
    }
	
    
	private static Scene createScene() {

        final Point3D cameraEye = new Point3D(0, 0, 100);
        final Point3D cameraLookAt = Point3D.ORIGIN;
        final Vector3D cameraUp = new Vector3D(0, 1, 0);

        final Point3D lightPosition = new Point3D(LIGHT_POSITION_X, LIGHT_POSITION_Y, LIGHT_POSITION_Z);

        final Point3D lowerPlanePoint = new Point3D(0, -20.1, 0);
        final Point3D upperPlanePoint = new Point3D(0, 30, 0);
        final Vector3D planeNormal = new Vector3D(0, 1, 0);

        final Sphere sphereObject1 = new Sphere(new Point3D(SPHERE1_ORIGIN_X, SPHERE1_ORIGIN_Y, SPHERE1_ORIGIN_Z), SPHERE1_RADIUS, Materials.metallic(ColorRGB.BLUE));
        final Sphere sphereObject2 = new Sphere(new Point3D(SPHERE2_ORIGIN_X, SPHERE2_ORIGIN_Y, SPHERE2_ORIGIN_Z), SPHERE2_RADIUS, Materials.metallic(ColorRGB.RED));        
        
        CSGObject object = new CSGObject(Materials.metallic(ColorRGB.PURPLE), sphereObject1, sphereObject2, Operation.SUBTRACTION_AB);
        
        final Plane upperPlane = new Plane(upperPlanePoint, planeNormal.multiply(-1), Materials.metallic(ColorRGB.WHITE));
        final Plane lowerPlane = new Plane(lowerPlanePoint, planeNormal, Materials.metallic(ColorRGB.YELLOW));
        
        final Light light = new Light(lightPosition);

        final Camera pinHoleCamera = new PinHoleCamera(cameraEye, cameraLookAt, cameraUp);
        pinHoleCamera.setZoomFactor(10);

        return new Scene().add(lowerPlane, upperPlane).add(light).setCamera(pinHoleCamera).add(object);
        
	}
	
}